/**
 * Created by happy on 2017/9/4.
 */


/*****
 * 图片选择
 * @param type
 */
function fileSelect(type) {
    if (type == 1) {
        document.getElementById("imgFile1").click();
    }
    if (type == 2) {
        document.getElementById("imgFile2").click();
    }
    if (type == 3) {
        document.getElementById("imgFile3").click();
    }
}


/**
 * 从 file 域获取 本地图片 url
 */
function getFileUrl(sourceId) {
    var url;
    if (navigator.userAgent.indexOf("MSIE") >= 1) { // IE
        url = document.getElementById(sourceId).value;
    } else if (navigator.userAgent.indexOf("Firefox") > 0) { // Firefox
        url = window.URL
            .createObjectURL(document.getElementById(sourceId).files
                .item(0));
    } else if (navigator.userAgent.indexOf("Chrome") > 0) { // Chrome
        url = window.URL
            .createObjectURL(document.getElementById(sourceId).files
                .item(0));
    }
    return url;
}

function preImg(sourceId, targetId) {
    var url = getFileUrl(sourceId);
    var imgPre = document.getElementById(targetId);
    imgPre.src = url;
    imgPre.width = 209;
    imgPre.height = 144;
}


function okSubmit(msg){
    parent.parent.window.parentOkSubmit(msg);
}
/******
 * 获取浏览器地址参数
 * @param name
 * @returns {null}
 */
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

function showTime(count, yzm) {
    if (count <= 0) {
        $("#" + yzm).attr("onclick", "sendVCode()");
        $("#" + yzm).text("获取短信验证码");
    } else {
        count -= 1;
        setTimeout(function() {
            $("#" + yzm).attr("onclick", "");
            $("#" + yzm).text("再次发送(" + count + ")秒");
            showTime(count, yzm);
        }, 1000);
    }
}